package com.gxa.service.impl;

import com.gxa.exception.CustomerException;
import com.gxa.mapper.DiseaselogMapper;
import com.gxa.pojo.Diseaselog;
import com.gxa.service.DiseaselogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA
 * User: bear
 * Date: 2020/09/25
 * Description
 * Version: V1.0
 */
@Service("diseaselogService")
@Transactional
public class DiseaselogServiceImpl implements DiseaselogService {
    @Resource
    DiseaselogMapper diseaselogMapper;

    @Override
    public Integer add(Diseaselog diseaselog) throws CustomerException {
        //自动设置添加时间（以当前添加的病情日志为准)
        diseaselog.setRecordTime(new Date());
        if (diseaselog.getRecordTime()==null||diseaselog.getRecordTime().equals("")){
            throw new CustomerException("日志时间不能为空");
        }
        if (diseaselog.getDes()==null||diseaselog.getDes().equals("")){
            throw new CustomerException("日志描述不能为空");
        }
        return diseaselogMapper.insert(diseaselog);
    }

    @Override
    public List<Diseaselog> findByPatientIdAll(Integer patientId) {
        return diseaselogMapper.findByPatientIdAll(patientId);
    }
}
